//
//  DelCollectionViewCell.m
//  WeatherGuide
//
//  Created by lanou3g on 15/12/24.
//  Copyright © 2015年 李明. All rights reserved.
//

#import "DelCollectionViewCell.h"

#import "Weather.h"
#import "DailyForecast.h"

@interface DelCollectionViewCell ()


@property (strong, nonatomic) IBOutlet UIImageView *condImageView;
@property (strong, nonatomic) IBOutlet UILabel *tmpLabel;


@end

@implementation DelCollectionViewCell

- (void)awakeFromNib {
    
}

- (void)setWeather:(Weather *)weather
{
    self.addImageView.image = nil;
    self.cityLabel.text = weather.city;
    
    for (int i = 1; i < 8; i++) {
        DailyForecast *dailyForecast = [weather valueForKey:[NSString stringWithFormat:@"dailyForecast%d",i]];
        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
        NSDate *date = [formatter dateFromString:dailyForecast.date];
        NSTimeInterval timeIndterval = [date timeIntervalSinceNow];
        if (timeIndterval < 60 * 60 * 24) {
            self.condImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png",dailyForecast.code_n]];
            if (dailyForecast.min.length != 0 && dailyForecast.max.length != 0) {
                self.tmpLabel.text = [NSString stringWithFormat:@"%@°~%@°",dailyForecast.min,dailyForecast.max];
            }else{
                self.tmpLabel.text = nil;
            }
        }
    }
}


@end
